package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.CashCoupon;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.CashCouponService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cashcoupon")
public class CashCouponController {

    @Autowired
    CashCouponService cashCouponService;

    @ApiOperation(value = "新增代金券", notes = "新增代金券")
    @ApiImplicitParam(name = "cashcoupon", value = "代金券对象", required = true, dataType = "Object")
    @PostMapping
    public Return<CashCoupon> save(CashCoupon cashcoupon){
        Return<CashCoupon> ret=new Return<>();
        if(cashCouponService.insert(cashcoupon)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


    @ApiOperation(value = "修改产品类型", notes = "修改产品类")
    @ApiImplicitParam(name = "activity", value = "代金券对象", required = true, dataType = "Object")
    @PutMapping
    public Return<CashCoupon> update(CashCoupon address){
        Return<CashCoupon> ret=new Return<>();
        if(cashCouponService.update(address)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


    @ApiOperation(value = "获取代金券列表", notes = "获取代金券列表")
    @GetMapping
    public Return<List<CashCoupon>> query(PageInfo pageInfo) {
        Return<List<CashCoupon>> ret = new Return<>();
        List<CashCoupon> cashCoupons = cashCouponService.query();
        ret.setData(cashCoupons);
        return ret;
    }
    @GetMapping(value = "/byCustomerId/{customerId}")
    public Return<List<CashCoupon>> queryByCustomerId(@PathVariable(value = "customerId") String customerId,Return ret){
        List<CashCoupon>  cashCoupons= cashCouponService.queryByCustomerId(customerId);
        ret.setData(cashCoupons);
        ret.getCommon().setRet(true);
        return ret;
    }

    @ApiOperation(value = "获取代金券", notes = "根据代金券ID获取代金券")
    @ApiImplicitParam(name = "cashCouponId", value = "代金券ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{cashCouponId}")
    public Return<CashCoupon> getCashCouponById(@PathVariable(value = "cashCouponId") String cashCouponId) {
        Return<CashCoupon> ret = new Return<>();
        CashCoupon cashCoupon = cashCouponService.queryById(cashCouponId);
        ret.setData(cashCoupon);
        return ret;
    }


    @ApiOperation(value = "删除代金券", notes = "根据代金券ID删除代金券")
    @ApiImplicitParam(name = "cashCouponIds", value = "代金券ID,多个用逗号隔开", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{cashCouponIds}")
    public Return<CashCoupon> delete(@PathVariable(value = "cashCouponIds") List<String> cashCouponIds) {
        Return<CashCoupon> ret = new Return<>();
        if(cashCouponService.deleteMore(cashCouponIds)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }






}
